import { useIntersectionObserver, useIntervalFn } from "@vueuse/core";
import { ref } from "vue";

export function useLazyData( callback : ()=> void){
  const target = ref(null)
  useIntersectionObserver(target,([{ isIntersecting }])=>{
      if(isIntersecting){
        callback()
      }
    
  },{
    threshold:0
  })
  return target
}

export function useCount(count:number){
  const time = ref(0)
  const { pause,resume } = useIntervalFn(()=>{
    time.value--
    if(time.value === 0) pause()
  },1000,{
    immediate:false
  })
  const start = ()=>{
    if(time.value > 0 )return
    time.value=5
    resume()
  }
  return {
    time,
    start
  }
}